﻿---@diagnostic disable: trailing-space
local extension = Package:new("moepack_ghost")
extension.extensionName = "moepack"

Fk:loadTranslationTable{
  ["moepack_ghost"] = "萌包-幽魅",
}





local emo__aoman = fk.CreateActiveSkill{
  name = "emo__aoman",
  anim_type = "offensive",
  min_card_num = 1,
  target_num = 1,
  card_filter = Util.TrueFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and Self.id ~= to_select and #selected_cards > 0
  end,
  prompt = "#emo__aoman-prompt",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isNude()
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local ids = room:recastCard(effect.cards, player, self.name)
    table.insertTableIfNeed(ids, effect.cards)
    local to = room:getPlayerById(effect.tos[1])
    if to.dead then return end
    local choice = room:askForChoice(to, {"emo__aoman_slash", "turnOver"}, self.name, "#emo__aoman-choice:"..player.id)
    if choice == "emo__aoman_slash" then
      for _, id in ipairs(ids) do
        if to.dead then break end
        if room:getCardArea(id) == Card.DiscardPile or table.contains(player.player_cards[Player.Hand], id) then
          if Fk:getCardById(id, true).trueName == "slash" then
            local slash = Fk:cloneCard(Fk:getCardById(id, true).name)
            slash:addSubcard(id)
            slash.skillName = self.name
            slash.suit = Card.NoSuit
            slash.color = Card.NoColor
            if not player:prohibitUse(slash) and not player:isProhibited(to, slash) then
              room:useCard{ from = player.id, card = slash, tos = {{to.id}}, extraUse = true}
            end
          end
        end
      end
    else
      to:turnOver()
    end
  end,
}
moe__luxifa:addSkill(emo__aoman)

Fk:loadTranslationTable{
  ["emo__aoman"] = "傲慢",
  [":emo__aoman"] = "出牌阶段限一次，你可以重铸任意张牌，并令一名其他角色选一项：1.你对其使用重铸和摸到的牌中所有的【杀】（视为无色）2.其翻面。",
  ["#emo__aoman-choice"] = "傲慢：选择翻面，或 %src 对你使用其使用重铸和摸到的牌中所有的【杀】",
  ["emo__aoman_slash"] = "被使用【杀】",
  ["#emo__aoman-prompt"] = "傲慢:重铸任意张牌，令一名其他角色选择被使用其中的【杀】或翻面",
}







--[[
等重做吧
local moe__nova = General:new(extension, "moe__nova", "moe", 3, 3, General.Female)

local emo__youdie = fk.CreateTriggerSkill{
  name = "emo__youdie",
  events = {fk.GameStart, fk.AfterCardTargetDeclared},
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return false end
    if event == fk.GameStart then return true end
    if (data.card:isCommonTrick() and target:getMark("@emo__butterfly") == "emo__confuse") or
    (data.card.type == Card.TypeBasic and target:getMark("@emo__butterfly") == "emo__bright") then
      return 
    end
  end,
  on_cost = function (self, event, target, player, data)
    if event == fk.GameStart then return true end
    local tos = {}
    if #tos > 0 then
      self.cost_data = tos
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart then
      local list = { {"heart,diamond", "emo__bright"}, {"spade,club", "emo__confuse"} }
      for _, dat in ipairs(list) do
        if player.dead then return end
        local ids = room:getCardsFromPileByRule(".|.|"..dat[1])
        if #ids > 0 then
          room:moveCardTo(ids, Player.Hand, player, fk.ReasonPrey, self.name)
        end
        if player.dead then return end
        local tos = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, 1,
        "#emo__youdie-choose:::"..dat[2], self.name, false)
        if #tos > 0 then
          room:setPlayerMark(room:getPlayerById(tos[1]), "@emo__butterfly", dat[2])
        end
      end
    else
      room:setPlayerMark(target, "@emo__butterfly", 0)
      room:sendLog{
        type = "#AddTargetsBySkill",
        from = data.from,
        to = {self.cost_data[1]},
        arg = self.name,
        arg2 = data.card:toLogString()
      }
      table.insert(data.tos, self.cost_data)
    end
  end,
}
moe__nova:addSkill(emo__youdie)

local emo__nonglin = fk.CreateTriggerSkill{
  name = "emo__nonglin",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    local mark = player:getTableMark("@emo__nonglin_color-turn")
    if player:hasSkill(self) and not player:isKongcheng() and #mark < 2 then
      local color = Fk:getCardById(player:getCardIds("h")[1]):getColorString()
      if not table.contains(mark, color) and color ~= "nocolor"
      and table.every(player:getCardIds("h"), function (id)
        return Fk:getCardById(id):getColorString() == color
      end) then
        for _, move in ipairs(data) do
          if move.to == player.id and move.toArea == Card.PlayerHand then
            return true
          end
          if move.from == player.id then
            for _, info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerHand then
                return true
              end
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local color = Fk:getCardById(player:getCardIds("h")[1]):getColorString()
    local mark = player:getTableMark("@emo__nonglin_color-turn")
    table.insert(mark, color)
    room:setPlayerMark(player, "@emo__nonglin_color-turn", mark)
    local name = color == "red" and "emo__bright" or "emo__confuse"
    player:showCards(player:getCardIds("h"))
    local tos = table.filter(room.alive_players, function(p) return p:getMark("@emo__butterfly") ~= name end)
    if #tos > 0 then
      local blank = table.filter(tos, function(p) return p:getMark("@emo__butterfly") == 0 end)
      if #blank > 0 then
        tos = blank
      end
      local to = table.random(tos)
      room:doIndicate(player.id, {to.id})
      room:setPlayerMark(to, "@emo__butterfly", name)
    end
    if player.dead then return end
    local pat = color == "red" and "spade,club" or "heart,diamond"
    local ids = room:getCardsFromPileByRule(".|.|"..pat, 1, "allPiles")
    if #ids > 0 then
      room:moveCardTo(ids, Player.Hand, player, fk.ReasonPrey, self.name, nil, true)
    end
  end,
}
moe__nova:addSkill(emo__nonglin)
--]]

Fk:loadTranslationTable{
  ["moe__nova"] = "诺瓦",
  ["#moe__nova"] = "贪爱的灵蝶",
  
  ["emo__youdie"] = "幽蝶",
  [":emo__youdie"] = "①游戏开始时，你摸一张红色牌，令一名角色获得“荧”标记，再摸一张黑色牌，令一名角色获得“惑”标记（每名角色仅能拥有一种）。"..
  "<br>②有“荧”/“惑”标记的角色使用基本牌/普通锦囊牌时，你可以移除此标记，为其指定一个额外目标。",
  ["@emo__butterfly"] = "",
  ["emo__bright"] = "<font color='#ff3300'>荧</font>",
  ["emo__confuse"] = "<font color='#888888'>惑</font>",
  ["#emo__youdie-choose"] = "幽蝶:令一名角色获得“%arg”标记",

  ["emo__nonglin"] = "弄鳞",
  [":emo__nonglin"] = "每回合每颜色限一次，当你失去或得到手牌时，若你的手牌为同一颜色，你可以展示手牌，随机令一名角色获得{红色：“荧”/黑色：“惑”}标记，然后获得另一颜色的一张牌。",
  ["@emo__nonglin_color-turn"] = "弄鳞",
}


-- lost
local moe__luosite = General:new(extension, "moe__luosite", "moe", 0, 0, General.Female)

local emo__youhun = fk.CreateTriggerSkill{
  name = "emo__youhun",
  frequency = Skill.Compulsory,
  events = {fk.HpChanged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.hp < 1
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player.hp < (0 - #room.players) then
      room:killPlayer{ who = player.id, damage = data.damageEvent }
    else
      data.preventDying = true
    end
  end,

  refresh_events = {fk.HpChanged, fk.EventLoseSkill, fk.BeforeGameOverJudge},
  can_refresh = function (self, event, target, player, data)
    if event == fk.HpChanged then
      return target == player and player:hasSkill(self, true)
    elseif event == fk.EventLoseSkill then
      return data == self and target == player
    else
      if target == player and player:hasSkill(self, false, true) then
        local e = player.room.logic:getCurrentEvent()
        return e.parent and e.parent.event == GameEvent.ChangeMaxHp
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if event == fk.BeforeGameOverJudge then
      -- 只能在这个时机拦截，Death事件的preapare没有拦截时机
      room:notifySkillInvoked(player, self.name, "defensive")
      room:setPlayerProperty(player, "dead", false)
      player._splayer:setDied(false)
      room:setPlayerProperty(player, "dying", false)
      room:setPlayerProperty(player, "hp", player.maxHp)
      table.insertIfNeed(room.alive_players, player)
      room.logic:getCurrentEvent().parent:shutdown()
    else
      -- 更新血条……
      local mark = 0
      if event ~= fk.EventLoseSkill and player.hp < 0 then
        mark = (player.hp) .. "/-" .. #room.players
      end
      room:setPlayerMark(player, "@emo__youhun", mark)
    end
  end,
}


local emo__youhun_maxcards = fk.CreateMaxCardsSkill{
  name = "#emo__youhun_maxcards",
  correct_func = function(self, player)
    if player:hasSkill(emo__youhun) then
      return #Fk:currentRoom().players
    end
  end,
}
emo__youhun:addRelatedSkill(emo__youhun_maxcards)

moe__luosite:addSkill(emo__youhun)

local emo__gouhun = fk.CreateTriggerSkill{
  name = "emo__gouhun",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local moveInfos = {}
    local cards = {{},{}}
    for _, p in ipairs(room:getOtherPlayers(player)) do
      for _, id in ipairs(p:getCardIds("hej")) do
        local card = Fk:getCardById(id)
        if card.type == Card.TypeBasic and card.color == Card.Red then
          table.insert(cards[1], id)
        elseif card.type ~= Card.TypeBasic and card.color == Card.Black then
          table.insert(cards[2], id)
        end
      end
    end
    local to_use = {}
    for _, cds in ipairs(cards) do
      if #cds > 0 then
        local get = table.random(cds)
        table.insert(to_use, get)
        table.insert(moveInfos, {
          ids = {get},
          from = room.owner_map[get],
          to = player.id,
          toArea = Player.Hand,
          moveReason = fk.ReasonPrey,
          moveVisible = false,
          proposer = player.id
        })
      end
    end
    local removed = #moveInfos < 2
    if #moveInfos > 0 then
      room:moveCards(table.unpack(moveInfos))
    end
    if player.dead then return end
    to_use = table.filter(to_use, function(id) return table.contains(player:getCardIds("h"), id) end)
    if #to_use > 0 and U.askForUseRealCard(room, player, to_use, ".", self.name, "#emo__gouhun-use") then
      removed = true
    end
    if removed and player:getMark("@@emo__gouhun_removed") == 0 then
      room:setPlayerMark(player, "@@emo__gouhun_removed", 1)
      room:addPlayerMark(player, MarkEnum.PlayerRemoved)
    end
  end,

  refresh_events = {fk.TurnStart},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@@emo__gouhun_removed") > 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@@emo__gouhun_removed", 0)
    player.room:removePlayerMark(player, MarkEnum.PlayerRemoved)
  end,
}
moe__luosite:addSkill(emo__gouhun)

local emo__suoming = fk.CreateTriggerSkill{
  name = "emo__suoming",
  anim_type = "offensive",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    local slash = Fk:cloneCard("slash")
    slash.skillName = self.name
    if player:hasSkill(self) and not player:prohibitUse(slash) then
      local room = player.room
      local tos = {}
      room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        for _, move in ipairs(e.data) do
          if move.from and move.from ~= player.id then
            local from = room:getPlayerById(move.from)
            if not from.dead and not player:isProhibited(from, slash) then
              for _, info in ipairs(move.moveInfo) do
                if info.fromArea == Card.PlayerEquip then
                  table.insertIfNeed(tos, move.from)
                  break
                end
              end
            end
          end
        end
        return #tos + 1 == #room.alive_players
      end, Player.HistoryTurn)
      if #tos > 0 then
        self.cost_data = tos
        return true
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local tos = player.room:askForChoosePlayers(player, self.cost_data, 1, 1, "#emo__suoming-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    local slash = Fk:cloneCard("slash")
    slash.skillName = self.name
    local use = {from = player.id, card = slash, tos = {{to.id}}, extraUse = true}
    room:useCard(use)
    if use.damageDealt and use.damageDealt[to.id] and not player.dead and not to.dead then
      local choices = {}
      local slots = to:getAvailableEquipSlots()
      if #slots > 0 then
        table.insert(choices, "#emo__suoming_abort")
      end
      if player:isWounded() then
        table.insert(choices, "#emo__suoming_recover:"..player.id)
      end
      if #choices == 0 then return end
      local choice = room:askForChoice(to, choices, self.name)
      if choice == "#emo__suoming_abort" then
        room:abortPlayerArea(to, table.random(slots))
      else
        room:recover { num = 1, skillName = self.name, who = player, recoverBy = player }
      end
    end
  end,
}
moe__luosite:addSkill(emo__suoming)

Fk:loadTranslationTable{
  ["moe__luosite"] = "洛丝特",
  ["#moe__luosite"] = "不祥之魂",
  
  ["emo__youhun"] = "幽魂",
  [":emo__youhun"] = "锁定技，你的手牌上限+X；当你扣减体力时，若你的体力值小于-X，你死亡，否则你不会进入濒死状态；防止你因扣减体力上限而死亡（X为本局角色数）。",
  ["@emo__youhun"] = "幽魂血:",

  ["emo__gouhun"] = "勾魂",
  [":emo__gouhun"] = "每当你受到伤害后，你可以从其他角色区域内随机获得一张红色基本牌和一张黑色非基本牌，若你此次获得的牌不足两张，或你使用了其中一张牌，你不计入座位直到下回合开始。",
  ["#emo__gouhun-use"] = "勾魂:你可以使用一张获得的牌，令你不计入座位直到下回合开始",
  ["@@emo__gouhun_removed"] = "勾魂中",

  ["emo__suoming"] = "索命",
  [":emo__suoming"] = "每回合结束时，你可以视为对本回合失去过装备区内的牌的一名其他角色使用一张【杀】，若此【杀】对其造成伤害，你令其选一项：1.随机废除一个装备栏；2.你回复一点体力。",
  ["#emo__suoming-choose"] = "索命：可视为对一名其他角色使用一张【杀】",
  ["#emo__suoming_abort"] = "随机废除一个装备栏",
  ["#emo__suoming_recover"] = "令 %src 回复一点体力",
}




local moe__daiya = General:new(extension, "moe__daiya", "moe", 4, 4, General.Female)

---@param player ServerPlayer
---@param add table|nil @ 添加记录的牌和角色id表
---@param remove integer|nil @ 移除记录的角色id
local updataHuanyu = function (player, add, remove)
  if player.dead then return end
  local room = player.room
  local mark = player:getTableMark("emo__huanyu_data")
  if add then
    table.insert(mark, add)
  end
  local data_mark, card_mark = {},{}
  for _, dat in ipairs(mark) do
    local temp = table.filter(dat[2], function (pid)
      local p = room:getPlayerById(pid)
      return not (p.dead and p.rest == 0) and pid ~= remove
    end)
    if #temp > 0 then
      table.insertIfNeed(card_mark, dat[1])
      table.insert(data_mark, {dat[1], temp})
    end
  end
  room:setPlayerMark(player, "emo__huanyu_data", data_mark)
  room:setPlayerMark(player, "@$emo__huanyu", #card_mark > 0 and card_mark or 0)
end

local emo__huanyu = fk.CreateTriggerSkill{
  name = "emo__huanyu",
  anim_type = "control",
  events = {fk.TargetSpecified, fk.TargetConfirmed, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player then
      if event == fk.TargetSpecified then
        if player.phase == Player.Play and data.firstTarget and (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) then
          local mark = player:getTableMark("emo__huanyu_data")
          return table.find(AimGroup:getAllTargets(data.tos), function (pid)
            return not table.find(mark, function(dat) return table.contains(dat[2], pid) end)
          end)
        end
      elseif event == fk.TargetConfirmed then
        if not (data.card:isVirtual() and #data.card.subcards == 0) and player.room:getCardArea(data.card) == Card.Processing 
        and player.phase == Player.NotActive then
          local mark = player:getTableMark("emo__huanyu_data")
          return table.find(mark, function(dat) return table.contains(dat[2], data.from) end)
        end
      else
        return player.phase == Player.Finish and #player:getTableMark("emo__huanyu_data") > 0
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      local mark = player:getTableMark("emo__huanyu_data")
      local targets = table.filter(AimGroup:getAllTargets(data.tos), function (pid)
        return not table.find(mark, function(dat) return table.contains(dat[2], pid) end)
      end)
      if #targets == 0 then return end
      if #targets == 1 then
        self.cost_data = targets
        return room:askForSkillInvoke(player, self.name, nil, "#emo__huanyu-chooseone::"..targets[1]..":"..data.card.name)
      else
        local tos = room:askForChoosePlayers(player, targets, 1, #targets, "#emo__huanyu-choose:::"..data.card.name, self.name, true)
        if #tos > 0 then
          self.cost_data = tos
          return true
        end
      end
    elseif event == fk.TargetConfirmed then
      local mark = player:getTableMark("emo__huanyu_data")
      local dat = table.find(mark, function(dat) return table.contains(dat[2], data.from) end)
      if dat then
        return room:askForSkillInvoke(player, self.name, nil, "#emo__huanyu-invoke::"..data.from..":"..data.card:toLogString()..":"..dat[1])
      end
    else
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetSpecified then
      updataHuanyu(player, {data.card.name, self.cost_data})
    elseif event == fk.TargetConfirmed then
      updataHuanyu(player, nil, data.from)
      room:moveCardTo(data.card, Player.Hand, player, fk.ReasonPrey, self.name)
    else
      local mark = player:getTableMark("emo__huanyu_data")
      for _, dat in ipairs(mark) do
        local card = Fk:cloneCard(dat[1])
        card.skillName = self.name
        local tos = table.filter(dat[2], function (pid)
          local p = room:getPlayerById(pid)
          return not p.dead and player:canUseTo(card, p, {bypass_distances = true, bypass_times = true}) 
        end)
        if #tos > 0 then
          room:useCard{
            from = player.id,
            tos = table.map(tos, function(p) return {p} end),
            card = card,
            extraUse = true,
          }
        end
        if player.dead then break end
      end
      updataHuanyu(player)
    end
  end,
}
moe__daiya:addSkill(emo__huanyu)

Fk:loadTranslationTable{
  ["moe__daiya"] = "黛鸦",
  ["#moe__daiya"] = "残梦的黑羽",
  
  ["emo__huanyu"] = "幻狱",
  [":emo__huanyu"] = "①当你于出牌阶段使用的基本牌或普通锦囊牌指定目标后，你可以记录任意名未被记录的目标角色，你的每个结束阶段，视为对这些角色使用此牌。"..
  "<br>②你的回合外，当你成为被“幻狱”记录角色使用的非虚拟牌的目标后，你可以获得此牌，移除其的记录。",
  ["#emo__huanyu-choose"] = "幻狱：可以记录任意目标角色，你每个结束阶段视为对其使用【%arg】",
  ["#emo__huanyu-chooseone"] = "幻狱：可以记录 %dest，你每个结束阶段视为对其使用【%arg】",
  ["@$emo__huanyu"] = "幻狱",
  ["#emo__huanyu-invoke"] = "幻狱：可以获得%arg，取消 %dest 的记录：【%arg2】",
}

local moe__xihe = General:new(extension, "moe__xihe", "moe", 3, 3, General.Female)

local emo__jielv = fk.CreateViewAsSkill{
  name = "emo__jielv",
  prompt = "#emo__jielv-prompt",
  pattern = ".|.|.|.|.|trick",
  expand_pile = function () return table.filter(Fk:currentRoom().discard_pile, function (id)
    return Fk:getCardById(id):isCommonTrick()
  end) end,
  card_filter = function(self, to_select, selected)
    if #selected == 0 and Fk:currentRoom():getCardArea(to_select) == Card.DiscardPile then
      local c = Fk:getCardById(to_select)
      return Self:canUse(c)
    end
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return nil end
    return Fk:getCardById(cards[1])
  end,
  before_use = function(self, player, use)
    player.room:setPlayerMark(player, "emo__jielv_invoked-phase", 1)
    use.extra_data = use.extra_data or {}
    use.extra_data.emo__jielv_user = player.id
  end,
  enabled_at_play = function(self, player)
    return table.every(player:getCardIds("h"), function (id)
      return Fk:getCardById(id).type ~= Card.TypeTrick
    end)
  end,
  enabled_at_response = Util.FalseFunc,
}

local emo__jielv_delay = fk.CreateTriggerSkill{
  name = "#emo__jielv_delay",
  mute = true,
  events = {fk.CardUseFinished, fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if event == fk.CardUseFinished then
      return (data.extra_data or {}).emo__jielv_user == player.id
    elseif not player.dead then
      local temp = player.room.logic:getCurrentEvent().parent
      local check
      while temp do
        if temp.event == GameEvent.UseCard then
          local use = temp.data[1]
          if use.extra_data and use.extra_data.emo__jielv_user == player.id then
            check = true
            break
          end
        end
        temp = temp.parent
      end
      if not check then return false end
      for _, move in ipairs(data) do
        if move.from and move.from ~= player.id and table.find(move.moveInfo, function (info)
            return info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip
          end) then
          return true
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUseFinished then
      local cards = table.filter(Card:getIdList(data.card), function (id)
        return room:getCardArea(id) == Card.Processing
      end)
      if #cards > 0 then
        room:moveCards({
          ids = cards,
          toArea = Card.DrawPile,
          moveReason = fk.ReasonPut,
          drawPilePosition = math.random(1, #room.draw_pile),
        })
      end
    else
      player:broadcastSkillInvoke("emo__jielv")
      room:notifySkillInvoked(player, "emo__jielv", "drawcard")
      for _, move in ipairs(data) do
        if move.from and move.from ~= player.id and table.find(move.moveInfo, function (info)
            return info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip
          end) then
          local from = room:getPlayerById(move.from)
          if not from.dead and from:getMark("@@emo__jielv-turn") == 0 then
            room:doIndicate(player.id, {from.id})
            room:setPlayerMark(from, "@@emo__jielv-turn", 1)
          end
        end
      end
      player:drawCards(1, "emo__jielv")
    end
  end,
}
emo__jielv:addRelatedSkill(emo__jielv_delay)

local emo__jielv_prohibit = fk.CreateProhibitSkill{
  name = "#emo__jielv_prohibit",
  is_prohibited = function(self, from, to, card)
    return to and to:getMark("@@emo__jielv-turn") > 0 and card and card.type == Card.TypeTrick
  end,
}
emo__jielv:addRelatedSkill(emo__jielv_prohibit)

moe__xihe:addSkill(emo__jielv)

local emo__yunli = fk.CreateTriggerSkill{
  name = "emo__yunli",
  anim_type = "support",
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and player:usedSkillTimes(self.name, Player.HistoryRound) == 0
    and table.find(player.room.alive_players, function (p)
      return not table.contains(player:getTableMark("emo__yunli_record"), p.id)
    end)
  end,
  on_cost = function (self, event, target, player, data)
    local targets = table.filter(player.room.alive_players, function (p)
      return not table.contains(player:getTableMark("emo__yunli_record"), p.id)
    end)
    if #targets == 0 then return false end
    local tos = player.room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#emo__yunli-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = {tos = tos}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data.tos[1])
    room:addTableMark(player, "emo__yunli_record", to.id)

    local all_choices = {"phase_draw", "phase_play", "phase_discard"}
    local choices = table.simpleClone(all_choices)
    local phaseList = {}
    for i = 1, 3 do
      local c = room:askForChoice(player, choices, self.name, "#emo__yunli-choice::"..to.id..":"..i, false, all_choices)
      table.removeOne(choices, c)
      table.insert(phaseList, c)
    end
    
    to:gainAnExtraTurn(true, self.name, { phase_table = table.map(phaseList, Util.PhaseStrMapper) })
  end,
}
moe__xihe:addSkill(emo__yunli)

Fk:loadTranslationTable{
  ["moe__xihe"] = "曦禾",
  
  ["emo__jielv"] = "节律",
  [":emo__jielv"] = "出牌阶段空闲时间点，若你手牌中没有锦囊牌，你可以使用弃牌堆中一张普通锦囊牌，此牌结算后洗入牌堆。每当一名其他角色在此牌结算中失去牌时，你摸一张牌，且该角色无法成为锦囊牌的目标直到回合结束。",
  ["@@emo__jielv-turn"] = "节律",
  ["#emo__jielv_delay"] = "节律",
  ["#emo__jielv-prompt"] = "节律:你可以使用弃牌堆中一张普通锦囊牌，此牌结束后洗入牌堆",

  ["emo__yunli"] = "云历",
  [":emo__yunli"] = "每名角色限一次，每轮限一次，你的回合结束时，你可以令一名角色执行一个仅有摸牌、出牌和弃牌阶段（顺序由你指定）的额外回合。",
  ["#emo__yunli-choose"] = "云历：你可以令一名角色执行一个仅有摸牌、出牌和弃牌阶段的额外回合",
  ["#emo__yunli-choice"] = "云历：请选择 %dest 执行额外回合的第 %arg 个阶段",
}

local moe__yaolianhua = General:new(extension, "moe__yaolianhua", "moe", 3, 3, General.Female)

local emo__fenzhi = fk.CreateActiveSkill{
  name = "emo__fenzhi",
  anim_type = "support",
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  prompt = "#emo__fenzhi-prompt",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:drawCards(2, self.name)
    if player.dead then return end
    local cards = {}
    player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move.to == player.id and move.toArea == Card.PlayerHand then
          for _, info in ipairs(move.moveInfo) do
            if table.contains(player.player_cards[Player.Hand], info.cardId) then
              table.insertIfNeed(cards, info.cardId)
            end
          end
        end
      end
      return false
    end, Player.HistoryTurn)
    if #cards == 0 then return end
    local max_limit = {#cards, #cards}
    if #room.alive_players < 2 then
      max_limit[2] = 0
    end
    local cardsMap = room:askForArrangeCards(player, self.name, {cards, "recast", "giveother"}, "#emo__fenzhi-arrange",
    true, 5, max_limit, {0, 0}, nil, nil, {cards, {}})
    local moveInfos = {}
    if #cardsMap[1] > 0 then
      table.insert(moveInfos, {
        ids = cardsMap[1],
        from = player.id,
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonRecast,
        skillName = self.name,
        moveVisible = true,
        proposer = player.id,
      })
    end
    if #cardsMap[2] > 0 then
      local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#emo__fenzhi-choose", self.name, false)
      if #tos > 0 then
        room:handleAddLoseSkills(room:getPlayerById(tos[1]), "emo__fenzhi_other&", nil, false, true)
        table.insert(moveInfos, {
          ids = cardsMap[2],
          from = player.id,
          to = tos[1],
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonGive,
          skillName = self.name,
          moveVisible = false,
          proposer = player.id,
          moveMark = "@@emo__fenzhi_other-inhand",
        })
      end
    end
    room:moveCards(table.unpack(moveInfos))
    if #cardsMap[1] > 0 then
      room:broadcastPlaySound("./audio/system/recast")
      room:sendLog{
        type = "#RecastBySkill",
        from = player.id,
        card = cardsMap[1],
        arg = self.name,
      }
      if not player.dead then
        player:drawCards(#cardsMap[1], self.name, nil, "@@emo__fenzhi-inhand-turn")
      end
    end
  end,
}

local emo__fenzhi_delay = fk.CreateTriggerSkill{
  name = "#emo__fenzhi_delay",
  events = {fk.TurnEnd},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return #player:getPile("emo__fenzhi") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:moveCardTo(player:getPile("emo__fenzhi"), Player.Hand, player, fk.ReasonPrey, self.name)
  end,

  refresh_events = {fk.PreCardUse, fk.AfterTurnEnd},
  can_refresh = function (self, event, target, player, data)
    if event == fk.PreCardUse then
      if target ~= player then return end
      local cardlist = Card:getIdList(data.card)
      return #cardlist > 0 and table.every(cardlist, function(id) return Fk:getCardById(id):getMark("@@emo__fenzhi-inhand-turn") > 0 end)
    else
      return target == player and player:hasSkill("emo__fenzhi_other&", true)
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if event == fk.PreCardUse then
      data.extraUse = true
      data.unoffsetableList = table.map(player.room.alive_players, Util.IdMapper)
    else
      room:handleAddLoseSkills(player, "-emo__fenzhi_other&", nil, false, true)
      for _, id in ipairs(player:getCardIds("h")) do
        local c = Fk:getCardById(id)
        if c:getMark("@@emo__fenzhi_other-inhand") > 0 then
          room:setCardMark(c, "@@emo__fenzhi_other-inhand", 0)
        end
      end
    end
  end,
}
emo__fenzhi:addRelatedSkill(emo__fenzhi_delay)

local emo__fenzhi_other = fk.CreateViewAsSkill{
  name = "emo__fenzhi_other&",
  anim_type = "control",
  pattern = "nullification",
  prompt = "#emo__fenzhi_other",
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type ~= Card.TypeBasic
    and Fk:getCardById(to_select):getMark("@@emo__fenzhi_other-inhand") > 0
  end,
  view_as = function(self, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("nullification")
    card.skillName = "emo__fenzhi"
    card:addSubcard(cards[1])
    return card
  end,
  enabled_at_response = function (self, player, response)
    return not response and table.find(player:getCardIds("h"), function (id)
      return Fk:getCardById(id):getMark("@@emo__fenzhi_other-inhand") > 0
    end)
  end,
}
Fk:addSkill(emo__fenzhi_other)

moe__yaolianhua:addSkill(emo__fenzhi)

local emo__fushang = fk.CreateTriggerSkill{
  name = "emo__fushang",
  events = {fk.HpChanged},
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.num < 0
    and not table.contains(player:getTableMark("@[list]emo__fushang"), player.hp)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local mark = player:getTableMark("@[list]emo__fushang")
    table.insert(mark, player.hp)
    room:setPlayerMark(player, "@[list]emo__fushang", mark)
    for i = 1, #mark do
      if player.dead then break end
      local card = Fk:cloneCard("analeptic")
      card.skillName = self.name
      if player:prohibitUse(card) or player:isProhibited(player, card) then break end
      local use = {from = player.id, tos = {{player.id}}, extraUse = true, card = card}
      if player.hp < 1 and player:isWounded() then
        use.extra_data = {analepticRecover = true}
      end
      room:useCard(use)
    end
    if not player.dead and not player.dying and data.damageEvent and data.damageEvent.from then
      local from = data.damageEvent.from
      if from and not from.dead and from ~= player then
        room:useVirtualCard("slash", nil, player, from, self.name, true)
      end
    end
  end,
}
moe__yaolianhua:addSkill(emo__fushang)

Fk:loadTranslationTable{
  ["moe__yaolianhua"] = "姚恋花",
  
  ["emo__fenzhi"] = "分治",
  [":emo__fenzhi"] = "出牌阶段限一次，你可以摸两张牌，再将本回合获得的牌分为重铸、交给一名其他角色的两组：因此重铸而摸到的牌于本回合不计入次数且无法被抵消；因此获得牌的其他角色可以将其中非基本牌当【无懈可击】使用直到其回合结束。",
  ["#emo__fenzhi-prompt"] = "分治：你可以摸两张牌，再重铸或交出本回合摸到的牌",
  ["#emo__fenzhi-arrange"] = "分治：你须将这些牌分为重铸、交给一名其他角色的两组",
  ["giveother"] = "交给他人",
  ["#emo__fenzhi-choose"] = "分治：选择一名其他角色，将分配的牌交给其",
  ["#emo__fenzhi_delay"] = "分治",
  ["@@emo__fenzhi-inhand-turn"] = "分治",
  ["@@emo__fenzhi_other-inhand"] = "分治",
  ["emo__fenzhi_other&"] = "分治",
  ["#emo__fenzhi_other"] = "你可以将“分治”牌中的非基本牌当【无懈可击】使用",
  [":emo__fenzhi_other&"] = "你可以将因〖分治〗获得的牌中的非基本牌当【无懈可击】使用，直到你回合结束。",

  ["emo__fushang"] = "浮觞",
  [":emo__fushang"] = "锁定技，每当你扣减体力后，若你当前的体力值未记录，你记录之并视为使用X张【酒】（X为记录的次数），然后若你不处于濒死状态且有伤害来源，你视为对其使用一张【杀】。",
  ["@[list]emo__fushang"] = "浮觞",
}

local moe__yangxue = General:new(extension, "moe__yangxue", "moe", 3, 3, General.Female)

local emo__niansheng = fk.CreateTriggerSkill{
  name = "emo__niansheng",
  anim_type = "control",
  events = {fk.RoundStart, fk.EnterDying},
  can_trigger = function (self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.RoundStart then return true end
      return not target.dead and target.dying and table.find(player:getCardIds("he"), function (id)
        return Fk:getCardById(id):getMark("@@emo__niansheng_card-round") ~= 0
      end) ~= nil
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    if event == fk.RoundStart then
      self.cost_data = nil
      return room:askForSkillInvoke(player, self.name)
    else
      local cards = table.filter(player:getCardIds("he"), function (id)
        return Fk:getCardById(id):getMark("@@emo__niansheng_card-round") ~= 0
      end)
      if #cards == 0 then return false end
      if room:askForSkillInvoke(player, self.name, nil, "#emo__niansheng-invoke::"..target.id..":"..(#cards)) then
        self.cost_data = {tos = {target.id}, cards = cards}
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.RoundStart then
      local x = player.maxHp - player:getHandcardNum()
      if x > 0 then
        player:drawCards(x, self.name)
      end
      if not player:isKongcheng() then
        local cards = room:askForCard(player, 1, 3, false, self.name, true, ".", "#emo__niansheng-card")
        if #cards > 0 then
          for _, id in ipairs(cards) do
            room:setCardMark(Fk:getCardById(id), "@@emo__niansheng_card-round", 1)
          end
        end
      end
    else
      local cards = table.simpleClone(self.cost_data.cards)
      room:recastCard(cards, player, self.name)
      if not target.dead then
        room:recover { num = #cards, skillName = self.name, who = target, recoverBy = player }
      end
    end
  end,
}

local emo__niansheng_maxcards = fk.CreateMaxCardsSkill{
  name = "#emo__niansheng_maxcards",
  exclude_from = function(self, player, card)
    return card and card:getMark("@@emo__niansheng_card-round") ~= 0 and player and player:hasSkill(emo__niansheng)
  end,
}
emo__niansheng:addRelatedSkill(emo__niansheng_maxcards)

moe__yangxue:addSkill(emo__niansheng)

local emo__fushu = fk.CreateTriggerSkill{
  name = "emo__fushu",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = {fk.AskForCardResponse},
  can_trigger = function (self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.pattern then
      if data.eventData and data.eventData.card then
        local users = (data.eventData.extra_data or {}).emo__fushu_users or {}
        if table.contains(users, player.id) then return end
        return Exppattern:Parse(data.pattern):matchExp("jink") or Exppattern:Parse(data.pattern):matchExp("slash")
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local dat = data.eventData
    dat.extra_data = dat.extra_data or {}
    dat.extra_data.emo__fushu_users = dat.extra_data.emo__fushu_users or {}
    table.insert(dat.extra_data.emo__fushu_users, player.id)
    if dat.from then
      room:doIndicate(player.id, {dat.from})
    end
    local names = table.filter({"jink","slash"}, function (name)
      return Exppattern:Parse(data.pattern):matchExp(name.."|0|nosuit|none")
    end)
    if #names == 0 then return end
    local name = room:askForChoice(player, names, self.name, "#emo__fushu-choice")
    local card = Fk:cloneCard(name)
    card.skillName = self.name
    if player:prohibitResponse(card) then return false end
    data.result = card
    return true
  end,
}
moe__yangxue:addSkill(emo__fushu)


Fk:loadTranslationTable{
  ["moe__yangxue"] = "阳雪",
  
  ["emo__niansheng"] = "念生",
  [":emo__niansheng"] = "每轮开始时，你可以摸牌至体力上限，标记至多三张手牌不计入手牌上限，本轮中每当一名角色进入濒死状态时，你可以重铸这些牌，每有一张令其回复1点体力。",
  ["#emo__niansheng-invoke"] = "念生：你可以重铸 %arg 张“念生”牌，令 %dest 回复等量体力",
  ["#emo__niansheng-card"] = "念生：标记至多三张手牌不计入手牌上限，本轮任何角色进入濒死时，你可以重铸之令其回血",
  ["@@emo__niansheng_card-round"] = "念生",

  ["emo__fushu"] = "弗殊",
  [":emo__fushu"] = "锁定技，当你需要打出【杀】或【闪】以响应一张牌时，你视为使用或打出之，且不能再以此法响应此牌。",
  ["#emo__fushu-choice"] = "弗殊：选择你要视为打出的牌",
}


local moe__reina = General:new(extension, "moe__reina", "moe", 4, 4, General.Female)

local emo__wenyi = fk.CreateTriggerSkill{
  name = "emo__wenyi",
  events = {fk.EventPhaseStart, fk.TargetConfirmed, fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(self) then return end
    if event == fk.EventPhaseStart then
      return player == target and player.phase == Player.Judge
    elseif event == fk.TargetConfirmed then
      return player == target and data.card.name ~= "slash" and data.card.trueName == "slash"
    else
      return not target.dead and #player.room.logic:getActualDamageEvents(1, function(e) return e.data[1].from == target end) == 0
    end
  end,
  on_cost = function(self, event, target, player, data)
    local prompt = "#emo__wenyi-lightning"
    if event == fk.TargetConfirmed then
      prompt = "#emo__wenyi-slash:::"..data.card:toLogString()
    elseif event == fk.TurnEnd then
      prompt = "#emo__wenyi-duel:"..target.id
    end
    return player.room:askForSkillInvoke(player, self.name, nil, prompt)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = 0
    if event == fk.EventPhaseStart then
      local judge = {
        who = player,
        reason = "lightning",
        pattern = ".|2~9|spade",
      }
      room:judge(judge)
      local result = judge.card
      if result.suit == Card.Spade and result.number >= 2 and result.number <= 9 then
        room:damage{
          to = player,
          damage = 3,
          damageType = fk.ThunderDamage,
          skillName = self.name,
        }
      end
      Fk.skills["#emo__wenyi_delay"]:use(fk.CardUseFinished, player, player, 
      {emo__wenyi_tem = player:getMark("emo__wenyi_tem-phase") })
      room:setPlayerMark(player, "emo__wenyi_tem-phase", 0)
    elseif event == fk.TargetConfirmed then
      data.additionalDamage = (data.additionalDamage or 0) + 1
      data.extra_data = data.extra_data or {}
      data.extra_data.emo__wenyi_tos = data.extra_data.emo__wenyi_tos or {}
      table.insert(data.extra_data.emo__wenyi_tos, player.id)
    else
      local card = Fk:cloneCard("duel")
      card.skillName = self.name
      local targets = table.filter(room.alive_players, function (p)
        return target:canUseTo(card, p)
      end)
      if #targets == 0 then return end
      local to = table.random(targets)
      local use = room:useCard({
        from = target.id, card = card, tos = {{to.id}}, extraUse = true, extra_data = {emo__wenyi_tos = {player.id}},
      })
    end
  end,

  refresh_events = {fk.Damaged},
  can_refresh = function(self, event, target, player, data)
    return target == player and data.skillName == self.name
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "emo__wenyi_tem-phase", data.damage)
  end,
}

local emo__wenyi_delay = fk.CreateTriggerSkill{
  name = "#emo__wenyi_delay",
  events = {fk.CardUseFinished},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return not player.dead and table.contains((data.extra_data or {}).emo__wenyi_tos or {}, player.id)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player.dead then return end
    local x = data.emo__wenyi_tem or (data.damageDealt or {})[player.id] or 0
    if x == 0 then
      if not player:isWounded() or room:askForChoice(player, {"draw2", "recover"}, "emo__wenyi") == "draw2" then
        player:drawCards(2, "emo__wenyi")
      else
        room:recover { num = 1, skillName = self.name, who = player, recoverBy = player }
      end
    else
      local tos = player.room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, x,
      "#emo__wenyi-choose:::"..x, self.name, true)
      if #tos > 0 then
        room:sortPlayersByAction(tos)
        for _, pid in ipairs(tos) do
          local p = room:getPlayerById(pid)
          if not p.dead then
            room:loseHp(p, 1, "emo__wenyi")
          end
        end
      end
    end
  end,
}
emo__wenyi:addRelatedSkill(emo__wenyi_delay)
moe__reina:addSkill(emo__wenyi)

Fk:loadTranslationTable{
  ["moe__reina"] = "澪奈",
  
  ["emo__wenyi"] = "瘟医",
  [":emo__wenyi"] = "判定阶段开始时，你可进行【闪电】判定；当你成为非普【杀】的目标后，你可令此牌伤害+1；一名角色的回合结束时，若其本回合未造成伤害，你可令其视为对随机角色使用一张【决斗】。"..
  "<br>以上的牌结算后，若未对你造成伤害，你选择回复一点体力或摸两张牌，若对你造成伤害，你可令至多X名角色各失去一点体力（X为受到的伤害值）。",

  ["#emo__wenyi_delay"] = "瘟医",
  ["#emo__wenyi-lightning"] = "瘟医：你可进行【闪电】判定",
  ["#emo__wenyi-slash"] = "瘟医：你可以令 %arg 伤害基数+1",
  ["#emo__wenyi-duel"] = "瘟医：你可令 %src 视为对随机角色使用【决斗】",
  ["#emo__wenyi-choose"] = "瘟医：你可令至多 %arg 名角色各失去一点体力",
}


local emo__yanwu = fk.CreateTriggerSkill{
  name = "emo__yanwu",
  anim_type = "drawcard",
  events = {fk.Damage, fk.Damaged},
  frequency = Skill.Compulsory,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local canDiscardNum = #table.filter(player:getCardIds("he"), function (id)
      return not player:prohibitDiscard(Fk:getCardById(id))
    end)
    local n1, n2 = 3 - player:getMark("emo__yanwu1"), 3 - player:getMark("emo__yanwu2")
    local all_choices = {"emo__yanwu1:::"..n1, "emo__yanwu2:::"..n2, "emo__yanwu3"}
    local choices = table.simpleClone(all_choices)
    if n1 < 1 then table.remove(choices, 1) end
    if n2 < 1 or canDiscardNum < n2 then table.removeOne(choices, all_choices[2]) end
    local choice = room:askForChoice(player, choices, self.name, "", false, all_choices)
    choice = choice:sub(1, 11)
    for i = 1, 3 do
      local mark = "emo__yanwu"..i
      if choice == mark then
        room:addPlayerMark(player, mark)
      else
        room:setPlayerMark(player, mark, 0)
      end
    end
    if choice == "emo__yanwu1" then
      player:drawCards(n1, self.name)
    elseif choice == "emo__yanwu2" then
      room:askForDiscard(player, n2, n2, true, self.name, false)
    else
      room:loseHp(player, 1, self.name)
      if player:isAlive() then
        local use = room:askForUseCard(player, "slash", "slash", "#emo__yanwu-slash", true)
        if use then
          use.extraUse = true
          room:useCard(use)
        end
      end
    end
  end
}
moe__zenith:addSkill(emo__yanwu)

Fk:loadTranslationTable{
  ["emo__yanwu"] = "演武",
  [":emo__yanwu"] = "锁定技，每当你造成或受到伤害后，你须选一项：1.摸3-X张牌；2.弃3-X张牌；3.失去1点体力然后可使用一张【杀】（X为连续选择此项的次数，初始为0）。",
  ["emo__yanwu1"] = "摸 %arg 张牌",
  ["emo__yanwu2"] = "弃 %arg 张牌",
  ["emo__yanwu3"] = "掉1血且可用【杀】",
  ["#emo__yanwu-slash"] = "演武：你可使用一张【杀】",
}


local moe__yalan = General:new(extension, "moe__yalan", "moe", 2, 3, General.Female)
moe__yalan.shield = 2

local emo__zhoujiu = fk.CreateTriggerSkill{
  name = "emo__zhoujiu",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if #room.discard_pile == 0 then return end
    local loseIds, losePlayers, inDiscards = {}, {}, {}
    room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move.from then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
              table.insertIfNeed(loseIds, info.cardId)
              table.insertIfNeed(losePlayers, move.from)
            end
          end
        end
        if move.toArea == Card.DiscardPile then
          for _, info in ipairs(move.moveInfo) do
            if room:getCardArea(info.cardId) == Card.DiscardPile then
              table.insertIfNeed(inDiscards, info.cardId)
            end
          end
        end
      end
      return false
    end, Player.HistoryTurn)
    if #losePlayers == 0 or #inDiscards == 0 then return end
    room:doIndicate(player.id, losePlayers)
    local cards = table.random(inDiscards, #losePlayers)
    room:delay(800)
    room:obtainCard(player, cards, true, fk.ReasonJustMove, player.id, self.name)
    cards = table.filter(cards, function (id)
      return table.contains(player:getCardIds("h"), id) and table.contains(loseIds, id)
    end)
    while #cards > 0 and not player.dead do
      local use = U.askForUseRealCard(room, player, cards, nil, self.name, "#emo__zhoujiu-use")
      if not use then break end
      table.removeOne(cards, use.card:getEffectiveId())
      cards = table.filter(cards, function (id)
        return table.contains(player:getCardIds("h"), id)
      end)
    end
  end,
}
moe__yalan:addSkill(emo__zhoujiu)

local emo__xuanxuan = fk.CreateTriggerSkill{
  name = "emo__xuanxuan",
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  events = { fk.Damaged },
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.from and not data.from.dead
    and player:usedSkillTimes(self.name) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = room:askForChoosePlayers(data.from, table.map(room.alive_players, Util.IdMapper), 1, 1,
    "#emo__xuanxuan-choose:"..player.id, self.name, false)
    local to = room:getPlayerById(tos[1])
    if #room:askForDiscard(to, 2, 2, true, self.name, true, nil, "#emo__xuanxuan-discard:"..player.id) < 2 then
      if not player.dead then
        room:recover { num = 1, skillName = self.name, who = player, recoverBy = player }
      end
    end
  end,
}
moe__yalan:addSkill(emo__xuanxuan)


Fk:loadTranslationTable{
  ["moe__yalan"] = "雅兰",
  
  ["emo__zhoujiu"] = "啁啾",
  [":emo__zhoujiu"] = "锁定技，每个回合结束时，本回合每有一名角色失去过牌，你便获得一张本回合进入弃牌堆的牌。若你获得了任一角色本回合失去过的牌，你可以使用之。",
  ["#emo__zhoujiu-use"] = "啁啾：你可以使用这些牌",

  ["emo__xuanxuan"] = "悬旋",
  [":emo__xuanxuan"] = "锁定技，每回合限一次，当你受到伤害后，令伤害来源指定一名角色，其需弃置两张牌，否则你回复1点体力。",
  ["#emo__xuanxuan-discard"] = "悬旋：请弃置两张牌，否则 %src 恢复1点体力",
  ["#emo__xuanxuan-choose"] = "悬旋：选择一名角色，其需弃2牌，否则 %src 恢复1点体力",
}

local moe__chengxi = General:new(extension, "moe__chengxi", "moe", 4, 4, General.Female)

local emo__caicai = fk.CreateTriggerSkill{
  name = "emo__caicai",
  events = {fk.EventPhaseStart},
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.phase == Player.Play
  end,
  on_cost = function(self, event, target, player, data)
    local targets = table.filter(player.room:getOtherPlayers(player), function (p) return not p:isKongcheng() end)
    if #targets == 0 then return false end
    local tos = player.room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 1, "#emo__caicai-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = tos[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    if to:isKongcheng() then return end
    local skills = {}
    for _, s in ipairs(to.player_skills) do
      if s:isPlayerSkill(to) then
        table.insertIfNeed(skills, s.name)
      end
    end
    local cards = {}
    for _, id in ipairs(to:getCardIds("h")) do
      local mark = Fk:getCardById(id):getMark("emo__caicai_card")
      if mark == 0 then
        table.insert(cards, id)
      else
        table.removeOne(skills, mark)
      end
    end
    while #cards > 0 and #skills > 0 do
      local cid = table.remove(cards, math.random(#cards))
      local skill = table.remove(skills, math.random(#skills))
      room:setCardMark(Fk:getCardById(cid), "emo__caicai_card", skill)
      room:setCardMark(Fk:getCardById(cid), "@emo__caicai_zh-inhand", Fk:translate(skill))
    end
    if player.dead then return end
    local ids = U.askforChooseCardsAndChoice(player, table.random(to:getCardIds("h"), 3), {"OK"}, self.name, "#emo__caicai-card", {}, 1, 1)
    local chosen = ids[1]
    local throw = room:askForDiscard(to, 1, 1, false, self.name, false)[1]
    if not (throw and throw == chosen) and table.contains(to:getCardIds("h"), chosen) and not player.dead then
      room:obtainCard(player, chosen, false, fk.ReasonPrey, player.id, self.name)
    end
  end,

  refresh_events = {fk.AfterCardsMove, fk.AfterTurnEnd},
  can_refresh = function (self, event, target, player, data)
    if event == fk.AfterCardsMove then
      return player == player.room.players[1]
    else
      return target == player and player:getMark("@[:]emo__caicai_skill") ~= 0
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if event == fk.AfterCardsMove then
      for _, move in ipairs(data) do
        if move.from then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerHand then
              local skill = Fk:getCardById(info.cardId):getMark("emo__caicai_card")
              if skill ~= 0 then
                room:setCardMark(Fk:getCardById(info.cardId), "emo__caicai_card", 0)
                local from = room:getPlayerById(move.from)
                if not from.dead and from.phase == Player.NotActive then
                  local mark = from:getTableMark("@[:]emo__caicai_skill")
                  table.insertIfNeed(mark, skill)
                  room:setPlayerMark(from, "@[:]emo__caicai_skill", mark)
                end
              end
            end
          end
        end
      end
    else
      room:setPlayerMark(player, "@[:]emo__caicai_skill", 0)
    end
  end,
}

local emo__caicai_invalidity = fk.CreateInvaliditySkill {
  name = "#emo__caicai_invalidity",
  invalidity_func = function(self, from, skill)
    return table.contains(from:getTableMark("@[:]emo__caicai_skill"), skill.name)
  end
}
emo__caicai:addRelatedSkill(emo__caicai_invalidity)

moe__chengxi:addSkill(emo__caicai)

Fk:loadTranslationTable{
  ["moe__chengxi"] = "橙汐",
  
  ["emo__caicai"] = "猜猜",
  [":emo__caicai"] = "出牌阶段开始时，你可以选择一名其他角色，令其拥有的每个技能各标记一张手牌（其于回合外失去被标记手牌时，令此牌对应的技能无效直到其回合结束）。然后你观看其三张手牌并选择一张，再令其弃置一张手牌，若其弃置的不为你选择的牌，你获得你选择的牌。",
  ["#emo__caicai-choose"] = "猜猜：选择一名其他角色，观看其手牌并令其弃牌",
  ["@emo__caicai_zh-inhand"] = "猜猜",
  ["@[:]emo__caicai_skill"] = "猜猜:封技",
  ["#emo__caicai-card"] = "猜猜：选择一张牌，若其没有弃置此牌，你获得之",
}

local moe__shayue = General:new(extension, "moe__shayue", "moe", 4, 4, General.Female)

local emo__dianzhen = fk.CreateTriggerSkill{
  name = "emo__dianzhen",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target.phase == Player.Judge and player:hasSkill(self) and target.hp >= player.hp
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#emo__dianzhen-invoke:"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "emo__dianzhen_invoked-phase", 1)
    room:doIndicate(player.id, {target.id})
    local cards = room:getNCards(2)
    room:moveCardTo(cards, Card.Processing, nil, fk.ReasonJustMove, self.name, nil, true, player.id)
    room:delay(200)
    local x = 1
    for _, id in ipairs(cards) do
      if room:getCardArea(id) == Card.Processing and Fk:getCardById(id).type == Card.TypeBasic and not player.dead and not target.dead then
        local card = Fk:cloneCard(x == 1 and "fire__slash" or "supply_shortage")
        card.skillName = self.name
        card:addSubcard(id)
        if not player:prohibitUse(card) and not player:isProhibited(target, card) then
          room:useCard{ from = player.id, card = card, tos = {{target.id}}, extraUse = true }
          x = 2
        end
      end
    end
    cards = table.filter(cards, function(id) return room:getCardArea(id) == Card.Processing end)
    if #cards > 0 then
      room:moveCards({
        ids = cards,
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonPutIntoDiscardPile,
        skillName = self.name,
        proposer = player.id,
      })
    end
  end,
}

local emo__dianzhen_delay = fk.CreateTriggerSkill{
  name = "#emo__dianzhen_delay",
  anim_type = "offensive",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    return player:getMark("emo__dianzhen_invoked-phase") > 0 and not target.dead 
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local all_choices = {"pindian", "fire_attack", "Cancel"}
    local choices = {"Cancel"}
    if player:canUseTo(Fk:cloneCard("fire_attack"), target) then
      table.insert(choices, 1, "fire_attack")
    end
    if player:canPindian(target) then
      table.insert(choices, 1, "pindian")
    end
    local choice = room:askForChoice(player, choices, "emo__dianzhen", "#emo__dianzhen-choice:"..target.id)
    if choice ~= "Cancel" then
      self.cost_data = choice
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ok
    if self.cost_data == "pindian" then
      local pd = player:pindian({target}, "emo__dianzhen")
      ok = (pd.results[target.id].winner == player)
    else
      local use = room:useVirtualCard("fire_attack", nil, player, target, "emo__dianzhen", true)
      ok = (use and use.damageDealt)
    end
    if ok and not player.dead then
      local n = 0
      room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        for _, move in ipairs(e.data) do
          if move.toArea == Card.DiscardPile then
            for _, info in ipairs(move.moveInfo) do
              n = n + 1
            end
          end
        end
        return false
      end, Player.HistoryPhase)
      if n > 0 then
        player:drawCards(n, "emo__dianzhen")
      end
    end
  end,
}
emo__dianzhen:addRelatedSkill(emo__dianzhen_delay)
moe__shayue:addSkill(emo__dianzhen)


Fk:loadTranslationTable{
  ["moe__shayue"] = "莎月",
  
  ["emo__dianzhen"] = "点阵",
  [":emo__dianzhen"] = "体力值不小于你的角色的判定阶段开始时，你可以亮出牌堆顶两张牌，将其中的基本牌分别当火【杀】、【兵粮寸断】对其使用，其余的牌置入弃牌堆，若如此做，此阶段结束时，你可以与其拼点或视为对其使用【火攻】，若你拼点赢或【火攻】造成伤害，你摸X张牌（X为本阶段进入弃牌堆的数）。",
  ["#emo__dianzhen-invoke"] = "点阵：你可以亮出牌堆顶两张牌，其中基本牌当【兵粮寸断】、火【杀】对 %src 使用",
  ["#emo__dianzhen_delay"] = "点阵",
  ["#emo__dianzhen-choice"] = "点阵：你可对 %src 拼点或使用【火攻】，若拼点赢或造成伤害则你可摸牌",
  ["pindian"] = "拼点",
}





local moe__zuoxi = General:new(extension, "moe__zuoxi", "moe", 3, 3, General.Female)

local emo__fengling = fk.CreateTriggerSkill{
  name = "emo__fengling",
  anim_type = "offensive",
  events = {fk.CardUsing, fk.RoundEnd},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.CardUsing then
      return player == target and player:hasSkill(self) and player.phase == Player.Play
      and data.card.trueName == "slash" and #TargetGroup:getRealTargets(data.tos) > 0
      and not (data.card:isVirtual() and #data.card.subcards == 0)
    else
      return player:hasSkill(self) and player:getMark("emo__fengling_record") ~= 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUsing then
      local tos = TargetGroup:getRealTargets(data.tos)
      if #tos == 0 then return end
      player:drawCards(#tos, self.name)
      if player.dead then return end
      local all_cards = Card:getIdList(data.card)
      local cards = table.filter(all_cards, function(id) return room:getCardArea(id) == Card.Processing end)
      local skillNames = {"__realcard"}
      if data.card:isVirtual() or data.card.name ~= Fk:getCardById(data.card.id, true).name then
        skillNames = data.card.skillNames
      end
      local mark = player:getTableMark("emo__fengling_record")
      -- 保留此牌数据：牌名，子卡，技能名，目标，额外伤害值
      table.insert(mark, {data.card.name, cards, skillNames, tos, data.additionalDamage or 0})
      room:setPlayerMark(player, "emo__fengling_record", mark)
      if #cards > 0 then
        player:addToPile(self.name, cards, true, self.name)
      end
      data.tos = {}
    else
      local mark = player:getMark("emo__fengling_record")
      for _, info in ipairs(mark) do
        if player.dead then return end
        local name, cards, skillNames, tos, damage = table.unpack(info)
        local pile = player:getPile(self.name)
        local card
        -- 此处用于检查使用的牌的子牌是否都在你武将牌上
        if skillNames[1] == "__realcard" then
          if #cards == 1 and table.contains(pile, cards[1]) then
            local c = Fk:getCardById(cards[1])
            if c.name == name then
              card = c
            end
          end
        else
          if table.every(cards, function(id) return table.contains(pile, id) end) then
            card = Fk:cloneCard(name)
            card:addSubcards(cards)
            card.skillNames = skillNames
          end
        end
        if card and not player:prohibitUse(card) then
          tos = table.filter(tos, function (pid)
            local p = room:getPlayerById(pid)
            return not p.dead and not player:isProhibited(p, card)
          end)
          if #tos > 0 then
            room:sortPlayersByAction(tos)
            local use = {from = player.id, tos = table.map(tos, function(p) return {p} end), card = card, extraUse = true,
            additionalDamage = damage > 0 and damage}
            room:useCard(use)
          end
        end
      end
      room:setPlayerMark(player, "emo__fengling_record", 0)
      room:moveCardTo(player:getPile(self.name), Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, "", nil, true)
    end
  end,

  refresh_events = {fk.PreCardUse},
  can_refresh = function (self, event, target, player, data)
    return player == target and player:hasSkill(self) and data.card.trueName == "slash" and player.phase == Player.Play
  end,
  on_refresh = function (self, event, target, player, data)
    data.noIndicate = true
  end,
}

local emo__fengling_targetmod = fk.CreateTargetModSkill{
  name = "#emo__fengling_targetmod",
  bypass_distances = function(self, player, skill)
    return skill.trueName == "slash_skill" and player:hasSkill(emo__fengling) 
  end,
  residue_func = function(self, player, skill, scope)
    if skill.trueName == "slash_skill" and player:hasSkill(emo__fengling) and scope == Player.HistoryPhase then
      return 1
    end
  end,
  extra_target_func = function(self, player, skill)
    if skill.trueName == "slash_skill" and player:hasSkill(emo__fengling) then
      return 1
    end
  end,
}
emo__fengling:addRelatedSkill(emo__fengling_targetmod)

moe__zuoxi:addSkill(emo__fengling)

local emo__qianxiang = fk.CreateTriggerSkill{
  name = "emo__qianxiang",
  anim_type = "defensive",
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.from ~= player.id and 
    data.card.type == Card.TypeTrick then
      local events = player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
        local use = e.data[1]
        return use.from == data.from and use.card.trueName == "slash"
      end, Player.HistoryTurn)
      if #events == 0 then
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, self.name)
  end,
}
moe__zuoxi:addSkill(emo__qianxiang)

Fk:loadTranslationTable{
  ["moe__zuoxi"] = "左汐",
  
  ["emo__fengling"] = "风铃",
  [":emo__fengling"] = "锁定技，你使用【杀】无距离限制且次数上限和目标上限+1。你于出牌阶段使用非虚拟【杀】时不声明目标，摸等于目标数的牌，并将此【杀】置于武将牌上，取消此【杀】的所有目标，改为本轮结束时对相同目标使用此【杀】。",

  ["emo__qianxiang"] = "浅象",
  [":emo__qianxiang"] = "每当你成为其他角色使用的锦囊牌的目标后，若其本回合未使用过【杀】，你可以摸一张牌。",
}


local emo__shangzhan = fk.CreateTriggerSkill{
  name = "emo__shangzhan",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      local tos = {}
      for _, move in ipairs(data) do
        if move.toArea == Card.DiscardPile and move.moveReason == fk.ReasonDiscard and move.from and move.from ~= player.id
          and player.room:getPlayerById(move.from).phase ~= Player.Play then
          table.insertIfNeed(tos, move.from)
        end
      end
      for _, pid in ipairs(tos) do
        if #player.room.logic:getActualDamageEvents(1, function(e)
          local damage = e.data[1]
          return damage.from == player and damage.to and damage.to.id == pid
        end, Player.HistoryRound) > 0 then
          return true
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, self.name)
  end,
}
moe__nemesis:addSkill(emo__shangzhan)

Fk:loadTranslationTable{
  ["emo__shangzhan"] = "赏战",
  [":emo__shangzhan"] = "锁定技，每当其他角色的手牌于其出牌阶段外被弃置时，若你本轮对其造成过伤害，你摸一张牌。",
}

local moe__moros = General:new(extension, "moe__moros", "moe", 5, 5, General.Female)

local emo__balu = fk.CreateTriggerSkill{
  name = "emo__balu",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.GameStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = {player}
    local targets = room:getOtherPlayers(player)
    local n = 2
    -- 选择是否指定其中一个目标
    if #targets > 2 then
      local t = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#emo__balu-choose", self.name, true, true)
      if #t > 0 then
        table.insert(tos, room:getPlayerById(t[1]))
        table.removeOne(targets, room:getPlayerById(t[1]))
        n = 1
      end
    end
    if #targets > 0 then
      table.insertTable(tos, table.random(targets, n))
    end
    room:doIndicate(player.id, table.map(tos, Util.IdMapper))
    for _, p in ipairs(tos) do
      room:setPlayerMark(p, "@@emo__balu", 1)
    end
    if n == 1 then
      room:loseHp(player, 1, self.name)
    end
  end,
}

local emo__balu_delay = fk.CreateTriggerSkill{
  name = "#emo__balu_delay",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing, fk.Death, fk.HpRecover},
  can_trigger = function(self, event, target, player, data)
    if player:getMark("@@emo__balu") == 0 or player.dead then return end
    if event == fk.CardUsing then
      if target == player and player.phase == Player.Play and (data.card.trueName == "slash" or data.card.type == Card.TypeEquip) then
        local use_events = player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
          local use = e.data[1]
          return use.from == player.id
        end, Player.HistoryTurn)
        return #use_events > 0 and use_events[1].data[1] == data
      end
    else
      return target ~= player and target:getMark("@@emo__balu") > 0
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.CardUsing then
      if data.card.trueName == "slash" then
        data.additionalDamage = (data.additionalDamage or 0) + 1
        if not data.extraUse then
          target:addCardUseHistory(data.card.trueName, -1)
          data.extraUse = true
        end
      else
        player:drawCards(2, "emo__balu")
      end
    else
      player:drawCards(event == fk.Death and 3 or 1, "emo__balu")
    end
  end,
}
emo__balu:addRelatedSkill(emo__balu_delay)

moe__moros:addSkill(emo__balu)

Fk:loadTranslationTable{
  ["moe__moros"] = "摩洛斯",
  ["#moe__moros"] = "命河渡使",
  
  ["emo__balu"] = "霸戮",
  [":emo__balu"] = "锁定技，游戏开始时，你随机选择两名其他角色（你可失去一点体力，将其中一名改为你指定），你与这些角色各获得“霸”标记，有“霸”标记的角色具有以下效果："..
  "<br>①使用出牌阶段第一张牌时：若为【杀】，则伤害+1且不计入次数，若为装备牌，则摸两张牌；"..
  "<br>②回复体力时/死亡时，其他有此标记的角色各摸一/三张牌。",
  ["#emo__balu_delay"] = "霸戮",
  ["@@emo__balu"] = "霸",
  ["#emo__balu-choose"] = "霸戮：你可失去一点体力，指定一名角色获得“霸”标记（具有加伤或摸牌效果）",
}


local moe__muyu = General:new(extension, "moe__muyu", "moe", 4, 4, General.Female)

local emo__pozhen = fk.CreateActiveSkill{
  name = "emo__pozhen",
  anim_type = "offensive",
  card_num = 0,
  target_num = 0,
  prompt = "#emo__pozhen-prompt",
  card_filter = Util.FalseFunc,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    -- 将角色与卡牌洗入九宫格
    local targets = table.map(room:getOtherPlayers(player), Util.IdMapper)
    if #targets > 9 then
      targets = table.random(targets, 9)
    end
    local card_num = 9 - #targets
    local cards = {}
    if card_num > 0 then
      cards = room:getNCards(card_num)
    end
    local targetsList = table.map(targets, function(id) return {"general", id} end)
    local cardsList = table.map(cards, function(id) return {"card", id} end)
    local list = table.connect(targetsList, cardsList)
    table.shuffle(list)
    -- 进行选择
    local result = room:askForCustomDialog(
      player, self.name,
      "packages/moepack/qml/PozhenBox.qml",
      { list , "#emo__pozhen"}
    )
    local choices = {}
    if result ~= "" then
      result = (result)
      choices = table.map(result, function(i) return list[i+1] end)
    end
    -- 分类选择的武将和牌
    local get, tos = {}, {}
    for _, dat in ipairs(choices) do
      if dat[1] == "general" then
        table.insert(tos, dat[2])
      else
        table.insert(get, dat[2])
      end
    end
    cards = table.filter(cards, function(id) return not table.contains(get, id) end)
    if #get > 0 then
      room:obtainCard(player, get, false, fk.ReasonJustMove, player.id, self.name)
      room:delay(500)
    end
    if #cards > 0 then
      room:moveCards({
        ids = cards,
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonPutIntoDiscardPile,
        skillName = self.name,
        proposer = player.id,
      })
    end
    if #tos > 0 then
      room:sortPlayersByAction(tos)
      room:doIndicate(player.id, tos)
      for _, pid in ipairs(tos) do
        local to = room:getPlayerById(pid)
        if not to.dead then
          room:damage { from = player, to = to, damage = 1, skillName = self.name }
        end
      end
    end
  end,
}
moe__muyu:addSkill(emo__pozhen)

Fk:loadTranslationTable{
  ["moe__muyu"] = "木瑜",
  
  ["emo__pozhen"] = "破阵",
  [":emo__pozhen"] = "出牌阶段限一次，你可以将所有存活其他角色随机置于九宫格中，其余位置用牌堆顶牌补全，然后你可选择九宫格中的一行或一列，你获得选择的牌，其余的牌置入弃牌堆，再对选择的角色各造成1点伤害。",
  ["#emo__pozhen"] = "破阵：请选择一行或一列",
  ["#emo__pozhen-prompt"] = "破阵：打开一个九宫格并选择一行或一列，获得选择的牌，对选择角色造成伤害",
}

local moe__yumeng = General:new(extension, "moe__yumeng", "moe", 3, 3, General.Female)
moe__yumeng.hidden = true

local emo__fumeng = fk.CreateActiveSkill{
  name = "emo__fumeng",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  frequency = Skill.Limited,
  card_filter = Util.FalseFunc,
  prompt = "#emo__fumeng-prompt",
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    local choices = {"#emo__fumeng_card", "#emo__fumeng_hp", "#emo__fumeng_skill", "Cancel"}
    local choice = room:askForChoice(to, choices, self.name, "#emo__fumeng-choice:"..player.id)
    if choice == choices[1] then
      U.swapCards(room, player, player, to, player:getCardIds("h"), to:getCardIds("h"), self.name)
      U.swapCards(room, player, player, to, player:getCardIds("e"), to:getCardIds("e"), self.name, Player.Equip)
    elseif choice == choices[2] then
      local tos = {player, to}
      local record = {to.maxHp, player.maxHp, to.hp, player.hp}
      for i, p in ipairs(tos) do
        room:changeMaxHp(p, record[i] - p.maxHp)
      end
      for i, p in ipairs(tos) do
        local num = record[i+2] - p.hp
        if not p.dead and num ~= 0 then
          if num > 0 then
            room:recover { num = num, skillName = self.name, who = p, recoverBy = player }
          else
            room:loseHp(p, -num, self.name)
          end
        end
      end
    elseif choice == choices[3] then
      MoeFunc.swapGeneralAndSkills(player, to)
    end
  end,
}
moe__yumeng:addSkill(emo__fumeng)

Fk:loadTranslationTable{
  ["moe__yumeng"] = "玉濛",

  ["emo__suiyuan"] = "邃愿",

  ["emo__fumeng"] = "赋梦",
  [":emo__fumeng"] = "限定技，出牌阶段，你可以选择一名其他角色，其可以选一项：1.与你交换手牌、装备区的牌；2.与你交换体力上限、体力值；3.与你交换武将、技能。",
  ["#emo__fumeng-prompt"] = "堕转：选择一名其他角色，其可以选择与你交换牌、体力或技能",
  ["#emo__fumeng-choice"] = "堕转：你可以与 %src 交换牌、体力或技能！",
  ["#emo__fumeng_card"] = "与你交换手牌、装备区的牌",
  ["#emo__fumeng_hp"] = "与你交换体力上限、体力值",
  ["#emo__fumeng_skill"] = "与你交换武将、技能",

  ["$emo__fumeng1"] = "请安心步入这良夜……",
  ["$emo__fumeng2"] = "可以安心交给我吗？",
}

local moe__ruoyin = General:new(extension, "moe__ruoyin", "moe", 3, 3, General.Female)

local emo__pianhui = fk.CreateActiveSkill{
  name = "emo__pianhui",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  prompt = function ()
    local last = Self:getMark("emo__pianhui_last")
    if last == 0 then
      return "#emo__pianhui-prompt"
    else
      return "#emo__pianhui-last:"..last
    end
  end,
  interaction = function()
    local choices = {}
    for _, s in ipairs({"black","red","equip"}) do
      local name = "emo__pianhui_"..s.."-phase"
      if Self:getMark(name) == 0 and Self:getMark(name) == 0 then
        table.insert(choices, "emo__pianhui_"..s)
      end
    end
    if #choices > 0 then
      return UI.ComboBox { choices = choices }
    end
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    local to = Fk:currentRoom():getPlayerById(to_select)
    if #selected == 0 and to then
      if self.interaction.data == "emo__pianhui_equip" then
        return #to:getCardIds("e") > 0
      else
        return not to:isKongcheng()
      end
    end
  end,
  can_use = function(self, player)
    return table.find({"black","red","equip"}, function (s)
      return player:getMark("emo__pianhui_"..s.."-phase") == 0
    end)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:setPlayerMark(player, self.interaction.data.."-phase", 1)
    local to = room:getPlayerById(effect.tos[1])
    local last = room:getPlayerById(player:getMark("emo__pianhui_last"))
    local cards = {}
    if self.interaction.data == "emo__pianhui_equip" then
      cards = to:getCardIds("e")
    else
      local black = self.interaction.data == "emo__pianhui_black"
      cards = table.filter(to:getCardIds("h"), function (id)
        if black then
          return Fk:getCardById(id).color == Card.Black
        else
          return Fk:getCardById(id).color == Card.Red
        end
      end)
    end
    if #cards > 0 then
      room:recastCard(cards, to, self.name)
      if not player.dead and last and not last.dead then
        cards = table.filter(cards, function(id) 
          if room:getCardArea(id) == Card.DiscardPile then
            local c = Fk:getCardById(id)
            return c.skill:getMinTargetNum() < 2 and player:canUseTo(c, last, {bypass_times = true, bypass_distances = true})
          end
          return false
        end)
        if #cards > 0 then
          local chosen = room:askForCardsChosen(player, to, 0, 1, { card_data = { { self.name, cards }  } }, self.name, 
          "#emo__pianhui-use:"..last.id)
          if #chosen > 0 then
            local c = Fk:getCardById(chosen[1])
            room:useCard{from = player.id, tos = {{last.id}}, card = c, extraUse = true}
          end
        end
      end
    end
    if not player.dead then
      room:setPlayerMark(player, "emo__pianhui_last", to.id)
      room:setPlayerMark(player, "@emo__pianhui_last", to.general)
    end
  end,
}
moe__ruoyin:addSkill(emo__pianhui)

local emo__kongwu = fk.CreateTriggerSkill{
  name = "emo__kongwu",
  events = {fk.TargetConfirmed, fk.CardUsing},
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.TargetConfirmed then
      if player:hasSkill(self) and target == player and data.from ~= player.id and data.card.color == Card.Black then
        local from = player.room:getPlayerById(data.from)
        return from and from.phase ~= Player.NotActive
      end
    else
      return player:hasSkill(self) and not target.dead and table.contains(target:getTableMark("@@emo__kongwu-turn"), player.id)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.TargetConfirmed then
      room:doIndicate(player.id, {data.from})
      local from = room:getPlayerById(data.from)
      local mark = from:getTableMark("@@emo__kongwu-turn")
      table.insertIfNeed(mark, player.id)
      room:setPlayerMark(from, "@@emo__kongwu-turn", mark)
    else
      room:doIndicate(player.id, {target.id})
      local mark = target:getTableMark("@@emo__kongwu-turn")
      table.removeOne(mark, player.id)
      room:setPlayerMark(target, "@@emo__kongwu-turn", #mark > 0 and mark or 0)
      local n = 3
      if not table.contains(TargetGroup:getRealTargets(data.tos), player.id) then
        n = 4
      end
      n = math.random(n)
      if n == 1 then
        room:loseHp(target, 1, self.name)
      elseif n == 2 then
        if not target:isNude() and not player.dead then
          local card = room:askForCard(target, 1, 1, true, self.name, false, ".", "#emo__kongwu-give:"..player.id)
          room:obtainCard(player, card, false, fk.ReasonGive, target.id, self.name)
        end
      elseif n == 3 then
        if data.toCard then
          data.toCard = nil
        else
          if data.card.type == Card.TypeTrick or data.card.sub_type == Card.SubtypeDelayedTrick then
            data.tos = {}
          else
            data.nullifiedTargets = table.map(room.players, Util.IdMapper)
          end
        end
      else
        if not target.dead then
          target:drawCards(1, self.name)
        end
        if not player.dead then
          player:drawCards(1, self.name)
        end
      end
    end
  end,

  refresh_events = {fk.BuryVictim, fk.EventLoseSkill},
  can_refresh = function (self, event, target, player, data)
    if table.contains(player:getTableMark("@@emo__kongwu-turn"), target.id) then
      return (event == fk.BuryVictim) or data == self
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local mark = player:getTableMark("@@emo__kongwu-turn")
    table.removeOne(mark, target.id)
    player.room:setPlayerMark(player, "@@emo__kongwu-turn", #mark > 0 and mark or 0)
  end,
}
moe__ruoyin:addSkill(emo__kongwu)

Fk:loadTranslationTable{
  ["moe__ruoyin"] = "若音",
  
  ["emo__pianhui"] = "偏晖",
  [":emo__pianhui"] = "出牌阶段每项限一次，你可以选一项令一名角色重铸：1.所有黑色手牌；2.所有红色手牌；3.装备区所有牌。然后你可以对此技能的上一个目标角色使用其中一张牌。",
  ["@emo__pianhui_last"] = "偏晖",
  ["emo__pianhui_black"] = "黑色手牌",
  ["emo__pianhui_red"] = "红色手牌",
  ["emo__pianhui_equip"] = "装备区牌",
  ["#emo__pianhui-use"] = "偏晖：你可以对 %src 使用其中一张牌！",
  ["#emo__pianhui-prompt"] = "偏晖：你可重铸一名角色的指定牌",
  ["#emo__pianhui-last"] = "偏晖：你可重铸一名角色的指定牌，然后可对 %src 使用其中一张牌",

  ["emo__kongwu"] = "空无",
  [":emo__kongwu"] = "锁定技，你成为其他角色于其回合内使用黑色牌的目标后，其本回合下一次使用牌时随机执行一项：1.失去一点体力；2.交给你一张牌；3.使用的牌无效；若使用的牌目标不含有你，添加一项：与你各摸一张牌。",
  ["@@emo__kongwu-turn"] = "空无",
  ["#emo__kongwu-give"] = "空无：请交给 %src 一张牌",
  ["#emo__kongwu_delay"] = "空无",
}










--[[

local moe__xxxx = General:new(extension, "moe__xxxx", "moe", 4, 4, General.Female)

Fk:loadTranslationTable{
  ["moe__xxxx"] = "",
  
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",

  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
}

--]]











return extension



